package cn.ctodb.im.client;

import cn.ctodb.im.dto.Command;
import cn.ctodb.im.dto.Packet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by cc on 2017/7/6.
 */
public class HeartBeatTasker implements Runnable {

    private Client client;
    private int waitTime = 10 * 1000;

    public HeartBeatTasker(Client client) {
        this.client = client;
    }

    @Scheduled(cron = "0/10 * *  * * ? ")
    public void exec() {

    }

    @Override
    public void run() {
        if (client.isRun()) {
            try {
                Packet packet = new Packet(Command.HEARTBEAT.cmd);
                client.send(packet);
            } catch (Throwable e) {

            } finally {
                try {
                    Thread.sleep(waitTime);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
